package com.ruoyi.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.CmsSiteDesigners;
import com.ruoyi.cms.service.ICmsSiteDesignersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设计师Controller
 * 
 * @author ruoyi
 * @date 2022-09-27
 */
@RestController
@RequestMapping("/cms/designers")
public class CmsSiteDesignersController extends BaseController
{
    @Autowired
    private ICmsSiteDesignersService cmsSiteDesignersService;

    /**
     * 查询设计师列表
     */
    @PreAuthorize("@ss.hasPermi('cms:designers:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsSiteDesigners cmsSiteDesigners)
    {
        startPage();
        List<CmsSiteDesigners> list = cmsSiteDesignersService.selectCmsSiteDesignersList(cmsSiteDesigners);
        return getDataTable(list);
    }

    /**
     * 导出设计师列表
     */
    @PreAuthorize("@ss.hasPermi('cms:designers:export')")
    @Log(title = "设计师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsSiteDesigners cmsSiteDesigners)
    {
        List<CmsSiteDesigners> list = cmsSiteDesignersService.selectCmsSiteDesignersList(cmsSiteDesigners);
        ExcelUtil<CmsSiteDesigners> util = new ExcelUtil<CmsSiteDesigners>(CmsSiteDesigners.class);
        util.exportExcel(response, list, "设计师数据");
    }

    /**
     * 获取设计师详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:designers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsSiteDesignersService.selectCmsSiteDesignersById(id));
    }

    /**
     * 新增设计师
     */
    @PreAuthorize("@ss.hasPermi('cms:designers:add')")
    @Log(title = "设计师", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsSiteDesigners cmsSiteDesigners)
    {
        return toAjax(cmsSiteDesignersService.insertCmsSiteDesigners(cmsSiteDesigners));
    }

    /**
     * 修改设计师
     */
    @PreAuthorize("@ss.hasPermi('cms:designers:edit')")
    @Log(title = "设计师", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsSiteDesigners cmsSiteDesigners)
    {
        return toAjax(cmsSiteDesignersService.updateCmsSiteDesigners(cmsSiteDesigners));
    }

    /**
     * 删除设计师
     */
    @PreAuthorize("@ss.hasPermi('cms:designers:remove')")
    @Log(title = "设计师", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsSiteDesignersService.deleteCmsSiteDesignersByIds(ids));
    }
}
